﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Log_out : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if(Session["user"] != null){
                LoadUserInfo();
                ConnectDB db = new ConnectDB();
                String username = Session["user"].ToString();
                if (db.getNumRequest(username) != -1)
                {
                    this.lblNumReq.Text = db.getNumRequest(username).ToString(); 
                }
                else
                {
                    this.lblNumReq.Text = "0";
                }
                
            }
            
        }
    }
    private void LoadUserInfo()
    {
        ProRegister pr = new ProRegister();
        String uid = Session["user"].ToString();
        //load cbb Department
        DataSet ds = pr.LoadUser(uid);
        this.lblFullName.Text = ds.Tables[0].Rows[0]["fullname"].ToString();
    }

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        Session["user"] = null;
        Session.Clear();
        Session.RemoveAll();
        Response.Redirect("Default.aspx");
    }
    protected void lbtnMyInfo_Click(object sender, EventArgs e)
    {
        Response.Redirect("Modifyacc.aspx");
    }
    protected void lbtnViewRequest_Click(object sender, EventArgs e)
    {
        if (this.lblNumReq.Text == "0")
        {
            Response.Redirect("RequestList.aspx?rql=0");
        }
        else 
        {
            Response.Redirect("RequestList.aspx?rql="+this.lblNumReq.Text);        
        }
    }
}
